//
//  WXPMineFAQView.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/25.
//
//

#import "WXPMineFAQView.h"

@interface WXPMineFAQView ()

@end

@implementation WXPMineFAQView

#pragma mark - lazy
- (UIView *)viewBack
{
    if (_viewBack == nil) {
        _viewBack = [UIView  new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        _viewBack.height = 135;
        _viewBack.userInteractionEnabled = true;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return  _viewBack;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.width = SCREEN_WIDTH;
        [self addSubView];
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self resetViewWithShowFAQ:false];
}

#pragma mark - 刷新view
- (void)resetViewWithShowFAQ:(BOOL)isShowFAQ{
    ModelBtn * modelFaq = [ModelBtn new];
    modelFaq.title = @"FAQ>";
    modelFaq.tag = 1;
    modelFaq.imageName = @"icon-mine-faq";
    modelFaq.width = self.viewBack.width/7*2;
    
    ModelBtn * modelSer = [ModelBtn new];
    modelSer.title = @"Servicio al cliente>";
    modelSer.imageName = @"icon-mine-ser";
    modelSer.tag = 2;
    modelSer.width = isShowFAQ ? self.viewBack.width/7*3 : self.viewBack.width/2;
    
    ModelBtn * modelQue = [ModelBtn new];
    modelQue.title = @"Queja>";
    modelQue.imageName = @"icon-mine-que";
    modelQue.tag = 3;
    modelQue.width =  isShowFAQ ? self.viewBack.width/7*2 : self.viewBack.width/2;
    
    NSMutableArray * list = [NSMutableArray new];
    if(isShowFAQ){
        [list addObject:modelFaq];
    }
    [list addObject:modelSer];
    [list addObject:modelQue];
    
    CGFloat left = 0;
    [self.viewBack removeAllSubViews];
    for (int i = 0; i < list.count; i ++) {
        ModelBtn * model = list[i];
        UIButton * view = [UIButton new];
        view.widthHeight = XY(model.width, self.viewBack.height);
        view.leftTop = XY(left, 0);
        left = view.right;
        [self.viewBack addSubview:view];
        UIImageView * image = [UIImageView new];
        image.widthHeight = XY(40, 40);
        image.image = [UIImage imageNamed:model.imageName];
        image.centerXTop = XY(view.width/2, 30);
        [view addSubview:image];
        UILabel * label = [UILabel new];
        [GlobalMethod setLabel:label widthLimit:0 isBold:true fontNum:14 textColor:COLOR_BLACK text:model.title];
        label.centerXTop = XY(image.centerX, image.bottom+16);
        [view addSubview:label];
        
        [view setNoRepeatActionWithInterval:1.0 action:^(UIButton * _Nonnull button) {
            if(model.tag == 1){
                [Global_Nav pushVCName:@"WXPMineFAQVC" animated:true];
            }
            if(model.tag == 2){
                [Global_Nav pushVCName:@"ServiceVC" animated:true];
            }
            if(model.tag == 3){
                [Global_Nav pushVCName:@"WXPComplainVC" animated:true];
            }
        }];
    }
    self.viewBack.centerXTop = XY(SCREEN_WIDTH/2, 0);
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}




@end
